#!/usr/bin/python

## This is created by Marco Da Col.
## Project started in 11/2011
## Version 0.0.1
## Official project page: 
## http://code.google.com/p/do-it-for-me 

#-----LIBRARY IMPORT-- 
import dircache
import re
import os.path
import os
import shutil
#--------------------

#-----MAIN-----------
#this is an ls on donwload folder
dir = dircache.listdir(DOWNLOAD_PATH)

i=0

for file in dir:
	if file[-4:]=='.avi':	#i'm interested only in .avi file for now
		#TODO Optimizing the REGEX is a taks
		data = re.match('([A-Z,a-z,\.]+(?=[s,S][0-9]{2}))([s,S][0-9]{2})([e,E][0-9]{2})', file)
		e = episode(data.group(1), data.group(2), data.group(3), file)
		destination_path = COMPLETE_PATH + e.getSerie() + '/' + 'Season ' + e.getSeason() + '/'
		
		#TODO Implement usefull error handling
		e.doCopy(DOWNLOAD_PATH, destination_path)
		print "Finished!"

#--------------------